﻿<?php 
class Zend_View_Helper_FromNowDateFormat extends Zend_View_Helper_Abstract{
    
    public function fromNowdateFormat($date){
	$format = "Y-m-d H:i";
	
	
        //print_r($date);die();
        if (is_object($date) && $date instanceof DateTime){
			$now = new DateTime();
			$dateTS = $date->getTimestamp();
			$nowTS = $now->getTimestamp();
			$diff = $nowTS - $dateTS;
            
            
            if($diff <= 3600){
                $minits = floor($diff/60);
                $str = $minits."м.";
            }elseif($diff < 86400 && $diff> 3600){
                $hours = floor($diff/3600);
                $minits = floor(($diff % 3600)/60);
                $str = $hours."ч. ".$minits."м.";
            }
            elseif($diff >= 86400 && $diff < 2592000){
                $hours = floor($diff/3600);
                $minits = floor(($diff % 3600)/60);
                $str = $hours."ч. ".$minits."м.";
            }
            
			
			elseif($diff > 2592000){
				$str = "более месяца";
			}
            
//            print ($date->getTimestamp());
        }else
            $strdate = $date;
		if (isset($str)){
			$result = $str;
		}else {
			$result = date($format,strtotime(date($format, $date->getTimestamp())));
		}
        return $result;

    }
}